<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购入库单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="col-sm-3">
                                <label>[[#{warehouse}]]：</label>
                                <div class="input-group">
                                    <input name="warehouseId" class="form-control" type="hidden">
                                    <input id="suggest-warehouse" class="form-control" type="text">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                            </li>
                            <li class="col-sm-3">
                                <label>[[#{supplier}]]：</label>
                                <div class="input-group">
                                    <input name="supplierId" class="form-control" type="hidden">
                                    <input id="suggest-supplier" class="form-control" type="text">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <label>[[#{inboundOrderNo}]]：</label>
                                <input type="text" name="inboundOrderNo"/>
                            </li>
                            <li>
                                <label>[[#{purchaseOrderNumber}]]：</label>
                                <input type="text" name="purchaseOrderNo"/>
                            </li>
                            <li>
                                <label>[[#{documentDate}]]：</label>
                                <input type="text" class="time-input" id="beginDocumentDate" th:placeholder="#{beginTime}" name="params[beginDocumentDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endDocumentDate" th:placeholder="#{endTime}" name="params[endDocumentDate]" />
                            </li>
                            <li>
                                <label>[[#{inboundType}]]：</label>
                                <select name="inboundType" th:with="type=${@dict.getType('jt_inbound_type')}">
                                    <option value="">[[#{all}]]</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>[[#{createTime}]]：</label>
                                <input type="text" class="time-input" id="beginCreateTime" th:placeholder="#{beginTime}" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endCreateTime" th:placeholder="#{endTime}" name="params[endCreateTime]" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;[[#{search}]]</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;[[#{reset}]]</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="purchase:inbound:add">
                    <i class="fa fa-plus"></i> [[#{add}]]
                </a>
                <a class="btn btn-info single disabled" onclick="inbound()" shiro:hasPermission="purchase:inbound:edit">
                    <i class="fa fa-edit"></i> [[#{confirmInbound}]]
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="purchase:inbound:edit">
                    <i class="fa fa-edit"></i> [[#{edit}]]
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="purchase:inbound:remove">
                    <i class="fa fa-remove"></i> [[#{delete}]]
                </a>

                <a class="btn btn-danger multiple disabled" onclick="cancel()" shiro:hasPermission="purchase:inbound:remove">
                    <i class="fa fa-remove"></i> 作废
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="purchase:inbound:export">
                    <i class="fa fa-download"></i> [[#{export}]]
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-suggest-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('purchase:inbound:edit')}]];
        var removeFlag = [[${@permission.hasPermi('purchase:inbound:remove')}]];
        var statusDatas = [[${@dict.getType('jt_inbound_status')}]];
        var inboundTypeDatas = [[${@dict.getType('jt_inbound_type')}]];
        var prefix = ctx + "business/purchase/inbound";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "采购入库单",
                sortName: "createTime",
                sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'inboundOrderId',
                    title: '采购入库单id',
                    visible: false
                },
                {
                    field: 'supplierName',
                    title: i18n('supplier')
                },
                {
                    field: 'warehouseName',
                    title: i18n('warehouse')
                },
                {
                    field: 'inboundOrderNo',
                    title: i18n('inboundOrderNo')
                },
                {
                    field: 'purchaseOrderNo',
                    title: i18n('purchaseOrderNumber')
                },
                {
                    field: 'documentDate',
                    title: i18n('documentDate'),
                    sortable:true
                },
                {
                    field: 'totalQty',
                    title: i18n('totalNumberOfInbound')
                },
                {
                    field: 'totalAmount',
                    title: i18n('theTotalAmountOfInbound')
                },
                {
                    field: 'status',
                    title: i18n('inboundStatus'),
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'inboundType',
                    title: i18n('inboundType'),
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(inboundTypeDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: i18n("remark")
                },
                {
                    field: 'createBy',
                    title: i18n("createBy")
                },
                {
                    field: 'createTime',
                    title: i18n("createTime"),
                    sortable:true
                },
                {
                    title: i18n("operate"),
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.inboundOrderId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.inboundOrderId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function inbound() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning(i18n('pleaseSelectAtLeastOne'));
                return;
            }

            $.modal.confirm("确认【入库】选中的" + rows.length + "条数据吗?", function() {
                var url = prefix + "/inbound";
                var data = { "inboundOrderId": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });
        }


        function cancel() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning(i18n('pleaseSelectAtLeastOne'));
                return;
            }

            $.modal.confirm("确认【作废】选中的" + rows.length + "条数据吗?", function() {
                var url = prefix + "/cancel";
                var data = { "ids": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });
        }
    </script>
     <script th:inline="javascript">
         var warehouseSuggest = $("#suggest-warehouse").bsSuggest({
             url: ctx + "business/warehouse/select/list",
             idField: "warehouseId",
             keyField: "warehouseName",
             clearable: true,
             ignorecase: true,
             hideOnSelect: true,
             effectiveFields: ["warehouseId", "warehouseName"],
             effectiveFieldsAlias: {warehouseId: "仓库ID", warehouseName: "仓库"},
         }).on('onSetSelectValue', function (e, selectedData, selectedRawData) {
             console.log('onSetSelectValue: ', selectedData);

             $("input[name='warehouseId']").val(selectedRawData.warehouseId);
         }).on('onUnsetSelectValue', function (e) {
             //console.log("onUnsetSelectValue=="+e);
             $("input[name='warehouseId']").val("");
         });


         var supplierSuggest = $("#suggest-supplier").bsSuggest({
             url: ctx + "business/supplier/select/list",
             idField: "supplierId",
             keyField: "supplierName",
             clearable: true,
             ignorecase: true,
             hideOnSelect: true,
             effectiveFields: ["supplierId", "supplierName","supplierCode"],
             effectiveFieldsAlias: {supplierId: "供应商ID", supplierName: "供应商名称", supplierCode:'供应商编码'},
         }).on('onSetSelectValue', function (e, selectedData, selectedRawData) {
             console.log('onSetSelectValue: ', selectedData);

             $("input[name='supplierId']").val(selectedRawData.supplierId);
         }).on('onUnsetSelectValue', function (e) {
             //console.log("onUnsetSelectValue=="+e);
             $("input[name='supplierId']").val("");
         });
    </script>
     <script th:inline="javascript">
         var ROOT = [[${#servletContext.contextPath}]];
         var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]];

         //初始化i18n
         $.i18n.properties({
             path: ROOT + '/i18n/',//这里表示访问路径
             name: 'messages',//文件名开头
             language: LANG_COUNTRY,//文件名语言 例如en_US
             mode: 'map'//默认值
         });

         //i18n函数
         function i18n(msgKey) {
             try {
                 return $.i18n.prop(msgKey);
             } catch (e) {
                 return msgKey;
             }
         }
     </script>
</body>
</html>